from flask_login import  UserMixin
from werkzeug.security import generate_password_hash, check_password_hash

from watchlist import db

# 继承 UserMixmin , 让 User 类拥有几个用于判断认证状态的方法


class User(db.Model, UserMixin): # 表名 user(自动处理)
    id = db.Column(db.Integer, primary_key=True) # 主键
    name = db.Column(db.String(20)) # 名字
    username = db.Column(db.String(20)) # 用户名
    password_hash = db.Column(db.String(20)) # 密码散列值

    def set_password(selef, password):
        selef.password_hash = generate_password_hash(password)
    
    def validate_password(selef, password):
        return check_password_hash(selef.password_hash, password)

class Movie(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(60))
    year = db.Column(db.String(4))
